Ext.define('PJ.view.messagemanagement.ReceiverList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.receiverList'],
    isHavePage:false,
    
    initComponent: function(){
    	var me = this;
        this.columns = [{
        	header: '登录号',
        	dataIndex: 'loginID',
        	width: 90
        },{
        	header: '姓名',
        	dataIndex: 'userName',
        	width: 110
        }, {
        	header: '单位',
        	dataIndex: 'depName',
        	flex: 1,
            minWidth: 110
        }, {
            header: '角色',
            dataIndex: 'roleName',
            width: 110
        }];
        this.store = Ext.create('PJ.' + prototype + '.messagemanagement.ReceiverList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    
    onDeleteClick: function(button){
        var me = this;
        var records = this.getSelectionModel().getSelection();
        Ext.Msg.confirm({
            title: '提示',
            msg: '您确定要删除该接收人吗？',
            buttons: Ext.Msg.OKCANCEL,
            fn: function(id){
            	if (id == 'ok') {
            		var records=me.getStore().getRange();
            		var selectModel=me.getSelectionModel();
            		for(var i=0;i<records.length;i++) {
            			var record=records[i];
            			if(selectModel.isSelected(record)) {
            				selectModel.deselect(record);
            			}else {
            				selectModel.select(record,true);	
            			}
            		}
            		var rec =  me.getSelectionModel().getSelection();
            		var userIds = new Array();
            		for(var i=0;i<rec.length;i++){
            			userIds.push(rec[i].get("userId"));
            		}
            		
                    var store = me.getStore();
                    var params = store.proxy.extraParams;
                    var newParams = {
                    		searchSelectedUserIds:userIds,
                    		searchClassIds: me.up('window').classId,
                    		searchSelectState:1
                    };
                    Ext.apply(params, newParams);
                    store.load();
                    
                    var stroe_rec = me.up('window').down("preReceiverList").getStore();
                    var params_rec = stroe_rec.proxy.extraParams;
                    var newParams_rec = {
                    		searchSelectedUserIds:userIds,
                    		searchClassIds: me.up('window').classId,
                    		searchSelectState:2
                    };
                    Ext.apply(params_rec, newParams_rec);
                    stroe_rec.load();
            		
            	}
                else {
                    return;
                }
            }
        });
    },

    listeners: {
        //点击列表数据时显示按钮事件
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + "Dele").setDisabled(selected.length === 0);//删除
    	},
        viewready: function(){
        	var me = this;
            this.addDocked([{
                dock: 'top',
                xtype: "searchform",
    			columnCount: 2,
    			collapsedFieldSet: true,
                fieldDefaults: {
                    xtype: "textfield",
                    labelAlign: 'right',
                    labelWidth: 80,
                    maxLength: 100
                },
                items: [{
                    fieldLabel: "登录号",
                    name: "searchLoginId",
                    emptyText: "请输入登录号"
                },{
                    fieldLabel: "姓名",
                    name: "searchUserName",
                    emptyText: "请输入姓名"
                },{
                    fieldLabel: "单位",
                    name: "searchDepName",
                    emptyText: "请输入单位"
                },{
    				xtype: "textfield",
    				fieldLabel: '角色',
    				name: "searchRoleCode",
    				maxLength: "50",
    				emptyText: "请输入角色"
    			}],
    			onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
                    		searchSelectedUserIds: me.up('window').userId,
                    		searchClassIds: me.up('window').classId,
                    		searchSelectState:1
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    form.getForm().reset();
                },
                grid: this
            },{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [/*this.updateButton, "-", */{
                    text: '删除',
                    iconCls: 'publishCancelIco',
                    itemId: this.oldId + "Dele",
                    disabled: true,
                    scope: this,
                    handler: this.onDeleteClick
                }, "->", "->", this.countSelectPanel]
            }]);
            var me = this;
            // 触发权限过滤事件
            me.fireEvent("permission", this);
            var params = me.store.proxy.extraParams;
            var newParams = {
            		searchSelectedUserIds: me.up('window').userId,
            		searchClassIds: me.up('window').classId,
            		searchSelectState:1
            };
            Ext.apply(params, newParams);
            this.store.isLoad = true;
            this.store.load();
        }
    }
});
